<template>
  <div>
    <!-- 面包屑导航器 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">订单管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!--卡片视图区-->
    <el-card>
      <!-- 搜索与添加区 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入订单编号" @clear="getOrders()" clearable v-model="queryInfo.query" class="input-with-select">
            <el-button  @click="getOrders()"  slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button @click="addDialogVisible = true" type="primary">添加订单</el-button>
        </el-col>
      </el-row>
      <!-- table区 -->
      <el-table :data="orderList" style="width: 100%" border stripe>
        <el-table-column  type="index" >
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号" >
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="80px">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="80px">
           <template slot-scope="scope">
               <el-tag type="success" v-if="scope.row.pay_status ==='1'" >已付款</el-tag>
               <el-tag type="danger" v-else>未付款</el-tag>
           </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="80px">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="150px">
           <template slot-scope="scope">
              {{scope.row.create_time | dateFormat}}
           </template>
        </el-table-column>
        <el-table-column label="操作" width="300px">
          <template>
            <!--修改订单地址-->
            <el-tooltip  effect="dark" content="修改订单地址" placement="top-start"  :enterable="false">
              <el-button @click="dzDialog = true" type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
            </el-tooltip>
            <!--物流-->
            <el-tooltip  effect="dark" content="物流" placement="top-start"  :enterable="false">
              <el-button @click="showWl" type="success"  icon="el-icon-location"  size="mini" >地址</el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>

    <!-- 修改地址对话框-->
    <el-dialog
      title="修改地址"
      :visible.sync="dzDialog"
      width="50%"
      @close="dzDialogClosed">
      <!--内容主体区域-->
      <el-form :model="azFrom" :rules="azFromRules" ref="azFromRef" label-width="120px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader :options="cityData" v-model="azFrom.address1">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="azFrom.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <!--内容底部按钮区域 点击了就隐藏对话框-->
        <el-button @click="dzDialog = false">取 消</el-button>
        <el-button  @click="dzDialog = false" type="primary">确 定</el-button>
        </span>
    </el-dialog>
    <!-- 物流进度对话框-->
    <el-dialog
      title="物流进度"
      :visible.sync="wlDialog"
      width="50%">
      <!--物流信息-->
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.timestamp">
          {{activity.content}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import citys from './citydata.js'
export default {
  data () {
    return {
      // 订单列表
      orderList: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      reverse: true,
      activities: [{
        content: '活动按期开始',
        timestamp: '2018-04-15'
      }, {
        content: '通过审核',
        timestamp: '2018-04-13'
      }, {
        content: '创建成功',
        timestamp: '2018-04-11'
      }],
      total: 0,
      dzDialog: false,
      wlDialog: false,
      wlList: [],
      azFrom: {
        address1: [],
        address2: ''
      },
      azFromRules: {
        address1: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      cityData: citys
    }
  },
  created () {
    this.getOrders()
  },
  methods: {
    // 获取所有订单列表
    async getOrders () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) return this.$message.error('获取订单数据失败')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrders()
    },
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrders()
    },
    dzDialogClosed () {
      this.$refs.azFromRef.resetFields()
    },
    async showWl () {
      this.wlDialog = true
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return this.$message.error('获取物流信息失败')
      this.wlList = res.data
    }
  }
}
</script>

<style scoped>

</style>
